﻿using System;
using Isotop.Text;
using NUnit.Framework;

namespace Isotop.Tests.Text
{
	[TestFixture]
	public class LazyStringBuilderTests
	{
		[Test]
		public void SimpleTest()
		{
			LazyStringBuilder sb = new LazyStringBuilder();
			sb.Append("a");
			sb.Append("b");
			Console.WriteLine(sb);
		}

		[Test]
		public void RemoveMiddle()
		{
			LazyStringBuilder sb = new LazyStringBuilder();
			sb.Append("a");
			sb.Append("b");
			sb.Append("c");
			sb.Remove(1, 1);
			Assert.That(sb.ToString(), Is.EqualTo("ac"));
		}

		[Test]
		public void RemoveFirst()
		{
			LazyStringBuilder sb = new LazyStringBuilder();
			sb.Append("a");
			sb.Append("b");
			sb.Append("c");
			//Console.WriteLine(sb);
			sb.Remove(0, 1);
			Assert.That(sb.ToString(), Is.EqualTo("bc"));
		}

		[Test]
		public void RemoveLast()
		{
			LazyStringBuilder sb = new LazyStringBuilder();
			sb.Append("a");
			sb.Append("b");
			sb.Append("c");
			sb.Remove(2, 1);
			Assert.That(sb.ToString(), Is.EqualTo("ab"));
		}

		[Test]
		public void RemoveOverMiddle()
		{
			LazyStringBuilder sb = new LazyStringBuilder();
			sb.Append("ab");
			sb.Append("c");
			sb.Append("de");
			sb.Remove(1, 2);
			Assert.That(sb.ToString(), Is.EqualTo("ade"));
		}

		[Test]
		public void RemoveOverMiddle2()
		{
			LazyStringBuilder sb = new LazyStringBuilder();
			sb.Append("ab");
			sb.Append("c");
			sb.Append("de");
			sb.Remove(1, 3);
			Assert.That(sb.ToString(), Is.EqualTo("ae"));
		}

		[Test, ExpectedException]
		public void ExcIndex()
		{
			LazyStringBuilder sb = new LazyStringBuilder();
			sb.Append("a");
			sb.Remove(1, 1);
		}

		[Test, ExpectedException]
		public void ExcLength()
		{
			LazyStringBuilder sb = new LazyStringBuilder();
			sb.Append("a");
			sb.Remove(0, 2);
		}
	}
}
